import axios from 'axios';

// 添加请求拦截器
// axios.interceptors.request.use(function (config) {
//   // Do something before request is sent
//   return config;
// }, function (error) {
//   // Do something with request error
//   return Promise.reject(error);
// });

// // 添加响应拦截器
// axios.interceptors.response.use(function (response) {
//   // Do something with response data
//   return response;
// }, function (error) {
//   // Do something with response error
//   return Promise.reject(error);
// });
axios.defaults.baseURL = 'http://www.carnivalwood.cn:3000/';
// axios.create({
//   baseURL: 'http:127.0.0.1:3000',
//   timeout: 1000,
//   headers: {'X-Custom-Header': 'foobar'}
// })

const request = (config) => {
  const {url, method ,params} = config;
  return axios
    .request(config)
    .then(response => Promise.resolve(response)) 
    .catch(error => Promise.reject(error));
}
export const get = (url, params) => {
  return request({
    url,
    method: 'GET',
    params
  })
}
export const post = (url, params) => {
  return request({
    url,
    method: 'POST',
    params
  })
}
export const put = (url, params) => {
  return request({
    url,
    method: 'PUT',
    params
  })
}
export const deletes = (url, params) => {
  return request({
    url,
    method: 'DELETE',
    params
  })
}

